package com.th.controller;

import com.th.pojo.Admin;
import com.th.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ThreePure
 * @date 2022/3/27 15:51
 * @description: TODO
 * @since 1.8
 */
@Controller
@RequestMapping("/admin")
public class AdminAction {

    //所有的界面层，一定有业务逻辑层的对象
    @Autowired
    AdminService adminService;


    /**
     * @description:  实现登录判断，并进行响应的跳转
     * @date 2022/3/27 15:55
     * @Param: []
     * @Return: java.lang.String
     */
    @RequestMapping("/login")
    public String login(String name, String pwd, HttpServletRequest request){
        Admin admin = adminService.login(name, pwd);
        if (admin != null){
            //登录成功，进入main.jsp
            request.setAttribute("admin", admin);
            return "main";
        }else {
            //登录失败，回到登录页面
            request.setAttribute("errmsg","用户名或密码不正确");
            return "login";
        }
    }
}
